package com.rocky_tech.framework.struts.form;

import java.awt.SystemColor;
import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class FullForm {
	public FullForm(){
		
	}
	
	public static ActionForm full (String formpath,HttpServletRequest request){
		ActionForm form = null;
		try{
			Class clazz = Class.forName(formpath);
			form = (ActionForm) clazz.newInstance();
			//通过反射，得到属性
			Field [] filed_ar = clazz.getDeclaredFields();
			//通过循环，来对每一个属性赋值
			for (Field f:filed_ar){
				f.setAccessible(true);
				//通过form的字段与页面上传递参数一一对应，来填充对象的属性值
				//<input type="text" name="userName">
				//Decide中的属性为userName
				f.set(form,request.getParameter(f.getName()));
				System.out.println(f.getName());
				System.out.println((request.getParameter(f.getName())));
				f.setAccessible(false);
			}
			System.out.println(form);
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("严重：Form装载失败！.....");
		}
		
		return form ; 
	}
}
